function generate() {
    const nInput = document.getElementById("nInput");
    const resultDiv = document.getElementById("result");

    const n = parseInt(nInput.value);

    if (isNaN(n) || n <= 0) {
        resultDiv.innerHTML = "<span style='color:red;'>请输入有效的正整数</span>";
        return;
    }

    let numbers = [];
    for (let i = 0; i < n; i++) {
        numbers.push(Math.floor(Math.random() * 101)); // 0 到 100
    }

    resultDiv.innerHTML = `<strong>生成结果：</strong><br>` + numbers.join(", ");
}